<template>
	<view>

		<!-- 使用自定义的搜索组件 -->
		<view class="search_box">
			<my-search @myclick="goToSearch"></my-search>
		</view>

		<!-- 使用自定义的搜索组件 结束 -->

		<!-- 轮播图开始-->
		<swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" circular="true">
			<swiper-item v-for="(item,index)  in swiperList">
				<navigator class="swiper-item" :url=" '/subpkg/goods_detail/goods_detail?goods_id='+item.goods_id ">
					<image :src="item.image_src" mode=""></image>
				</navigator>
			</swiper-item>

		</swiper>
		<!-- 轮播图结束-->

		<!-- 分类导航开始 -->
		<view class="nav-list">
			<view class="nav-item" v-for="(item,index) in navList" @click="navClickHandler(item)">
				<image class="nav-img" :src="item.image_src" mode=""></image>
			</view>
		</view>
		<!-- 分类导航结束 -->

		<!-- 楼层区域 -->
		<!-- 楼层的容器 -->
		<view class="floor_list">
			<!-- 楼层的 item项 -->
			<view class="floor_item" v-for="(item,index) in floorList">
				<!-- 楼层的标题 -->
				<image :src="item.floor_title.image_src" mode="" class="floor_title"></image>

				<!-- 楼层的图片区域 -->
				<view class="floor_img_box">
					<!-- 左侧大图片的盒子 -->
					<navigator class="left_image_box" :url="item.product_list[0].url">
						<image :src="item.product_list[0].image_src"
							:style=" {width:item.product_list[0].image_width  +'rpx'} " mode="widthFix"></image>
					</navigator>
					<!-- 右侧4个小图片的盒子 -->
					<view class="right_image_box">
						<navigator class="roght_img_item" v-for="(item2,index2) in  item.product_list" :key="index2"
							v-if="index2!==0" :url="item2.url">
							<image :src="item2.image_src" mode="widthFix" :style="{width:item2.image_width +'rpx'}">
							</image>
						</navigator>
					</view>
				</view>
			</view>
		</view>
		<!-- 楼层区域 结束-->

	</view>
</template>

<script>
	
	import badgeMix from '@/mixins/tabbar-badge.js'
	export default {
		mixins:[badgeMix],
		data() {
			return {
				//轮播图数据
				swiperList: [],
				//分类导航数据
				navList: [],
				//楼层数据
				floorList: [],
			}
		},
		onLoad() {
			this.getSwiperList();
			this.getNavList();
			this.getFloorList();
		},
		methods: {

			async getSwiperList() {
				const {
					data: res
				} = await uni.$http.get('/api/public/v1/home/swiperdata');
				console.log("res", res);
				//请求失败
				if (res.meta.status !== 200) {
					return uni.$showMsg();
				}
				uni.$showMsg("数据请求成功-----" + res.message)
				this.swiperList = res.message;
			},

			async getNavList() {
				const {
					data: res
				} = await uni.$http.get('/api/public/v1/home/catitems')
				//请求失败
				if (res.meta.status !== 200) {
					return uni.$showMsg();
				}

				// uni.$showMsg("数据请求成功-----" + res.message)
				this.navList = res.message
			},
			async getFloorList() {
				const {
					data: res
				} = await uni.$http.get("/api/public/v1/home/floordata");

				if (res.meta.status !== 200) {
					return uni.$showMsg();
				}

				res.message.forEach(function(floor, index, data) {
					floor.product_list.forEach(function(product, index2, data2) {
						product.url = "/subpkg/goods_list/goods_list?" + product.navigator_url.split(
							"?")[1]
					})
				})
				this.floorList = res.message
			},
			navClickHandler(item) {
				if ("分类" === item.name) {
					uni.switchTab({
						url: "/pages/cate/cate"
					})
				}
			},
			goToSearch() {
				uni.navigateTo({
					url: "/subpkg/search/search"
				})
			},
		}
	}
</script>

<style lang="scss">
	.search_box {
		position: sticky;
		top: 0;
		z-index: 100;
	}

	swiper {
		height: 330rpx;

		.swiper-item,
		image {
			width: 100%;
			height: 100%;
		}
	}

	.nav-list {
		display: flex;
		justify-content: space-around;
		margin: 30rpx 0px;

		.nav-img {
			width: 128rpx;
			height: 140rpx;
		}
	}

	.floor_title {
		width: 100%;
		height: 60rpx;
	}

	.floor_img_box {
		display: flex;
		padding-left: 10rpx;
	}

	.right_image_box {
		display: flex;
		justify-content: space-around;
		flex-wrap: wrap;
	}
</style>
